package com.megagoodsoftware.MediaShare;

import java.io.*;

import android.content.*;
import android.database.*;
import android.net.*;
import android.provider.*;

public class MediaShareFile {
	private Uri uri;
	private String name;
	private int size;
	private ContentResolver resolver;
	private final static String[] META_COLUMNS = {
		OpenableColumns.DISPLAY_NAME,
		OpenableColumns.SIZE
	};

	public MediaShareFile(ContentResolver resolver, Uri uri) {
		this.uri = uri;
		this.resolver = resolver;
		getMetadata();
	}

	private void getMetadata() {
		size = 0;
		name = "Unknown";
		Cursor metadataCursor = resolver.query(uri,
				META_COLUMNS, null, null, null);
		if (metadataCursor != null) {
			try {
				if (metadataCursor.moveToFirst()) {
					name = metadataCursor.getString(0);
					size = metadataCursor.getInt(1);
				}
			} finally {
				metadataCursor.close();
			}
		}
	}
	
	public InputStream openInputStream() throws FileNotFoundException {
		return resolver.openInputStream(uri);
	}
	
	public String getName() {
		return name;
	}

	public int getSize() {
		return size;
	}

}
